package com.flamingskys.learn.rag.es.service;

import com.flamingskys.learn.rag.es.entity.Product;
import com.flamingskys.learn.rag.es.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ProductService {

    private final ProductRepository productRepository;

    @Autowired
    public ProductService(ProductRepository productRepository) {
        this.productRepository = productRepository;
    }

    public Product saveProduct(Product product) {
        return productRepository.save(product);
    }

    public Page<Product> searchProducts(String query, Pageable pageable) {
        return productRepository.findByName(query, pageable);
    }

    public void deleteProduct(String id) {
        productRepository.deleteById(id);
    }
}